package com.ruoyi.web.controller.travel;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Result;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.travel.domain.TravelConsult;
import com.ruoyi.travel.service.ITravelConsultService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

@RestController
@RequestMapping("/travel/consult")
public class TravelConsultController extends BaseController
{
    @Autowired
    private ITravelConsultService travelConsultService;

    /**
     * 查询咨询管理列表
     */
    @PreAuthorize("@ss.hasPermi('travel:consult:list')")
    @GetMapping("/list")
    public TableDataInfo list(TravelConsult travelConsult)
    {
        startPage();
        List<TravelConsult> list = travelConsultService.selectTravelConsultList(travelConsult);
        return getDataTable(list);
    }

    /**
     * 获取咨询管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('travel:consult:query')")
    @GetMapping(value = "/{consultId}")
    public AjaxResult getInfo(@PathVariable("consultId") Long consultId)
    {
        return success(travelConsultService.selectTravelConsultByConsultId(consultId));
    }

    /**
     * 新增咨询管理
     */

/*
获得咨询的列表只有查询管理可以获得
 */
    @PreAuthorize("@ss.hasPermi('travel:consult:add')")
    @Log(title = "咨询管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TravelConsult travelConsult)
    {
        return toAjax(travelConsultService.insertTravelConsult(travelConsult));
    }

    /**
     * 修改咨询管理
     */
    @PreAuthorize("@ss.hasPermi('travel:consult:edit')")
    @Log(title = "咨询管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TravelConsult travelConsult)
    {
        return toAjax(travelConsultService.updateTravelConsult(travelConsult));
    }

    /**
     * 批量分配定制师
     */
    @PutMapping("/assignDesigner")
    public AjaxResult assignDesigner(@RequestParam("consults") List<Long> consults,
                                     @RequestParam("designerId") Long designerId) {
        int count = travelConsultService.assignDesigner(consults, designerId);
        return toAjax(count);
    }

    /**
     * 批量退回定制师
     */
    @PutMapping("/rejectDesigner")
    public AjaxResult rejectDesigner(@RequestParam("consults") List<Long> consults,
                                     @RequestParam("designerId") Long designerId) {
        int count = travelConsultService.assignDesigner(consults, designerId);
        return toAjax(count);
    }


    /**
     * 删除咨询管理
     */
    @PreAuthorize("@ss.hasPermi('travel:consult:remove')")
    @Log(title = "咨询管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{consultIds}")
    public AjaxResult remove(@PathVariable Long[] consultIds)
    {
        return toAjax(travelConsultService.deleteTravelConsultByConsultIds(consultIds));
    }


    @GetMapping("/designerName")
    public AjaxResult designerName(@RequestParam("consults") List<Long> consults,
                                     @RequestParam("designerId") Long designerId) {
        int count = travelConsultService.designerName(consults, designerId);
        return toAjax(count);
    }
}
